package com.ruoyi.project.search.viewOutJobHistory.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.search.viewOutJobHistory.domain.ViewOutJobHistory;
import com.ruoyi.project.search.viewOutJobHistory.service.IViewOutJobHistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库流水Controller
 * 
 * @author ruoyi
 * @date 2023-08-30
 */
@Controller
@RequestMapping("/search/viewOutJobHistory")
public class ViewOutJobHistoryController extends BaseController
{
    private String prefix = "search";

    @Autowired
    private IViewOutJobHistoryService viewOutJobHistoryService;

    @GetMapping()
    public String viewOutJobHistory()
    {
        return prefix + "/viewOutJobHistory";
    }

    /**
     * 查询出库流水列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewOutJobHistory viewOutJobHistory)
    {
        startPage();
        List<ViewOutJobHistory> list = viewOutJobHistoryService.selectViewOutJobHistoryList(viewOutJobHistory);
        return getDataTable(list);
    }

    /**
     * 导出出库流水列表
     */
    @Log(title = "出库流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewOutJobHistory viewOutJobHistory)
    {
        List<ViewOutJobHistory> list = viewOutJobHistoryService.selectViewOutJobHistoryList(viewOutJobHistory);
        ExcelUtil<ViewOutJobHistory> util = new ExcelUtil<ViewOutJobHistory>(ViewOutJobHistory.class);
        return util.exportExcel(list, "出库流水数据");
    }

    /**
     * 新增出库流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库流水
     */
    @Log(title = "出库流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewOutJobHistory viewOutJobHistory)
    {
        return toAjax(viewOutJobHistoryService.insertViewOutJobHistory(viewOutJobHistory));
    }

    /**
     * 修改出库流水
     */
    @GetMapping("/edit/{jobDetailId}")
    public String edit(@PathVariable("jobDetailId") String jobDetailId, ModelMap mmap)
    {
        ViewOutJobHistory viewOutJobHistory = viewOutJobHistoryService.selectViewOutJobHistoryByJobDetailId(jobDetailId);
        mmap.put("viewOutJobHistory", viewOutJobHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库流水
     */
    @Log(title = "出库流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewOutJobHistory viewOutJobHistory)
    {
        return toAjax(viewOutJobHistoryService.updateViewOutJobHistory(viewOutJobHistory));
    }

    /**
     * 删除出库流水
     */
    @Log(title = "出库流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewOutJobHistoryService.deleteViewOutJobHistoryByJobDetailIds(ids));
    }
}
